#include <rtdevice.h>
#include <rtthread.h>
#include <board.h>
#include "w25q64_qspi.h"

void test_w25q64(void)
{
    uint8_t write_data[256] = {0xAA, 0xBB, 0xCC, 0xDD};
    uint8_t read_data[256] = {0};
    uint32_t id;
    uint32_t address = 0x000000;
    
    // Initialize QSPI interface
    MX_OCTOSPI1_Init();
    
    // Read ID
    id = W25Q64_ReadID();
    rt_kprintf("Flash ID: 0x%06lX\n", id);
    
    // Erase sector
    W25Q64_SectorErase(address);
    
    // Write data
    W25Q64_PageProgram(address, write_data, sizeof(write_data));
    
    // Read back
    W25Q64_Read(address, read_data, sizeof(read_data));
    
    // Verify
    for(int i = 0; i < sizeof(write_data); i++)
    {
        rt_kprintf("Write: 0x%02X, Read: 0x%02X\n", write_data[i], read_data[i]);
    }

    if(rt_memcmp(write_data, read_data, sizeof(write_data)) == 0)
    {
        rt_kprintf("Data verification successful\n");
    }
}

MSH_CMD_EXPORT(test_w25q64, test_w25q64);
